#include "sock.hpp"
#include <string>
int main(int args, char *argv[])
{
    if (args != 3)
    {
        cout << args << endl;
        printf("ip port\n");
        exit(3);
    }
    // 测试版
    // Udp_myshell s;
    // int sock = s.Create();
    // char buffer[1024];
    // cout << argv[1] << endl;
    // sockaddr_in serve;
    // serve.sin_addr.s_addr = inet_addr(argv[1]);
    // serve.sin_family = AF_INET;
    // serve.sin_port = htons(atoi(argv[2]));
    // while (true)
    // {
    //     std::cin >> buffer;
    //     sendto(sock, buffer, sizeof(buffer), 0, (sockaddr *)(&serve), sizeof(serve));
    // }
    // myshell版
    std::string comd; 
    char buffer[BUFFER_NUM];
    Udp_myshell client;
    int sock = client.Create();
    sockaddr_in serve;
    serve.sin_family = AF_INET;
    serve.sin_port = htons(atoi(argv[2]));
    serve.sin_addr.s_addr = inet_addr(argv[1]);
    sockaddr_in servesock;
    socklen_t len = sizeof(servesock);
    while (true)
    {
        printf("#请输入你的命令:");
        fflush(stdout);
        std::getline(std::cin, comd);
        ssize_t s = sendto(sock, comd.c_str(), comd.size(), 0, (sockaddr *)(&serve), sizeof(serve));
        s = recvfrom(sock, buffer, BUFFER_NUM, 0, (sockaddr *)(&servesock), &len);
        cout << buffer << endl;
        memset(buffer, 0, BUFFER_NUM);
    }
    return 0;
}
